﻿using System;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    public partial class FrmParamDetails : BaseForm
    {
        public FrmParamDetails(string id)
        {
            InitializeComponent();
            tabPane.RecordId = id;
        }

        public FrmParamDetails(GridControlPlus gridControl)
        {
            InitializeComponent();
            tabPane.Grid = gridControl;
        }

        private async void Form_Load(object sender, EventArgs e)
        {
            await tabPane.BindingModelAsync();
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            DialogCancel();
        }

        private void TabPane_PageBinding(object sender, DetailsFormPaneBindingEventArgs e)
        {
            e.Task = async () =>
            {
                switch (e.Current.TabPageName)
                {
                    case nameof(tabBasic):
                        bindingSource.DataSource = string.IsNullOrEmpty(e.Current.Id) ? new SysParam() : await SysParamService.Instance.SelectByIdAsync(e.Current.Id);
                        break;
                    case nameof(tabHistoryLog):
                        await historyLogGrid.LoadAsync(nameof(SysParam), e.Current.Id);
                        break;
                }
            };
        }
    }
}